<template>
	
	<pageOrder v-show="tab.current === 0" />
	<pageMine v-if="tab.current === 1" />
	
	
	<view class="bpad"></view>
	<view class="bpad"></view>
	<view class="bottom">
		<view class="orderactions bgf t-flex between pt20 pb20 pr30 pl30" v-if="!tab.current">
			<view class="btn t-flex center f30 cf" @click="$go('/pages/workerClient/order/verificationList')">核销记录</view>
			<view class="t-flex center scan f30 cf" @click="scan">
				<image src="../../static/icons/30.png" mode="aspectFit" class="icon" ></image>扫码核销
			</view>
		</view>
		<view class="tabbar bgf ">
			<view class="t-flex between safeArea f24 c9">
				<view class="item t-flex colum" v-for="item,index in tab.list" :key="index" :class="{'active':tab.current == index}"
				@click="tab.change(index)"
				>
					<image :src="tab.current == index?item.selectIcon:item.icon" mode="aspectFit" class="icon"></image>
					<view>{{item.name}}</view>
				</view>
			</view>
		</view>
	</view>
	

</template>

<script setup lang="ts">
import pageMine from "./order/mine.vue"
import pageOrder from "./order/order.vue"
import { reactive } from 'vue';
import { onReady,onPullDownRefresh,onReachBottom } from "@dcloudio/uni-app"
import { showToast } from "../../lib/ts/util";
import { hxOrder } from "../../api";

	
	onReady(()=>{
		
	})
	onPullDownRefresh(()=>{
		if(tab.current){
			
		}else{
			uni.$emit('orderPageOnPullDownRefresh')
		}
	})
	onReachBottom(()=>{
		if(tab.current){
			
		}else{
			uni.$emit('orderPageOnReachBottom')
		}
	})

	
	let tab = reactive({
		list:[
			{name:'订单',icon:'/static/icons/19.png',selectIcon:'/static/icons/20.png'},
			{name:'我的',icon:'/static/icons/21.png',selectIcon:'/static/icons/22.png'}
		],
		current:0,
		change(e:number){
			tab.current = e
			uni.pageScrollTo({
				scrollTop:0,
				duration:0
			})
		}
	})
	
	
	//扫码核销
	const scan = ()=>{
		uni.scanCode({
			async success(e) {
				if(e.result){
					let header = e.result.split('?')[0]
					let arr = e.result.split('?')[1].split('&')
					let params = {}
					arr.forEach(item=>{
						params[item.split('=')[0]] = item.split('=')[1]
					})
					
					if(header != 'jzbl') return showToast('错误的核销码')
					let res = await hxOrder(params.id)
					showToast(res.msg)
					uni.$emit('orderPageOnPullDownRefresh')
				}
			}
		})
	}
	

</script>

<style scoped lang="scss">
	.bottom{
		position: fixed;
		bottom: 0;
		width: 100%;
		z-index: 500;
	}
	.tabbar{
		padding: 10rpx 60rpx;
		border-top: 1px solid #f5f6f7;
		.icon{
			width: 48rpx;
			height: 48rpx;
		}
		.item{
			width: 40%;
		}
	}
	.item.active{
		color: $main-color;
	}
	
	.orderactions{
		.btn{
			width: 240rpx;
			height: 92rpx;
			background: #FDA602;
			border-radius: 50rpx;
		}
		.scan{
			width: 420rpx;
			height: 92rpx;
			background: #E40417;
			border-radius: 50rpx;
			.icon{
				width: 48rpx;
				height: 48rpx;
				margin-right: 20rpx;
			}
		}
	}
	
	
	
</style>
